<?php
require '../h2o.php';
require_once 'Benchmark/Timer.php';
require 'context.php';

$person = array('name'=>'taylor', 'age'=>18, 'hobbies'=>array('watch tv','swimming', 'walking', 'kick boxing'));

define('ITERATION', 10000);


$c = new H2o_Context(compact('person'));
$c2 = new H2o_Context_old(compact('person'));

$bm = new Benchmark_Timer(true);


for ($i=0;$i<ITERATION;$i++)
    $c->resolve('person.name');

$bm->setMarker('Resolve associative array');
    
for ($i=0;$i<ITERATION;$i++)
    $c->resolve('person.hobbies.first');

$bm->setMarker('Resolve array shortcut #first');

for ($i=0;$i<ITERATION;$i++)
    $c->resolve('person.hobbies.last');

$bm->setMarker('Resolve array shortcut #last');

for ($i=0;$i<ITERATION;$i++)
    $c->resolve('person.hobbies.length');

$bm->setMarker('Resolve array shortcut #length');

for ($i=0;$i<ITERATION;$i++)
    $c->resolve('person.undefined');

$bm->setMarker('Undefined variable');
echo $bm->display();

$bm = new Benchmark_Timer(true);

for ($i=0;$i<ITERATION;$i++)
    $c2->getVariable('person.name');
$bm->setMarker('OLD Resolve associative array');
    
for ($i=0;$i<ITERATION;$i++)
    $c2->getVariable('person.hobbies.first');

$bm->setMarker('OLD Resolve array shortcut #first');

for ($i=0;$i<ITERATION;$i++)
    $c2->getVariable('person.hobbies.last');

$bm->setMarker('OLD Resolve array shortcut #last');

for ($i=0;$i<ITERATION;$i++)
    $c2->getVariable('person.hobbies.length');

$bm->setMarker('OLD Resolve array shortcut #length');

for ($i=0;$i<ITERATION;$i++)
    $c2->getVariable('person.undefined');

$bm->setMarker('OLD Undefined variable');

echo $bm->display();

?> 